//package com.wiloon.java8x.mocking;
//
//import org.junit.Test;
//import org.mockito.ArgumentMatcher;
//import org.mockito.Mockito;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.LinkedList;
//import java.util.List;
//
//import static org.mockito.Mockito.*;
//
////Let's import Mockito statically so that the code looks clearer
//
///**
// * Created by USER on 2015/8/14;
// */
//public class MockitoX {
//    private final static Logger logger = LoggerFactory.getLogger(MockitoX.class);
//
//    @Test
//    public void test0() {
//
//        //mock creation
//        List mockedList = mock(List.class);
//
//        //using mock object
//        mockedList.add("one");
//        mockedList.clear();
//
//        //verification
//        verify(mockedList).add("one");
//        verify(mockedList).clear();
//    }
//
//    @Test
//    public void stub() {
//        //You can mock concrete classes, not only interfaces
//        LinkedList mockedList = mock(LinkedList.class);
//
//        //stubbing
//        when(mockedList.get(0)).thenReturn("first");
//        when(mockedList.get(1)).thenThrow(new RuntimeException());
//
//        //following prints "first"
//        System.out.println(mockedList.get(0));
//
//        //following throws runtime exception
//        // System.out.println(mockedList.get(1));
//
//        //following prints "null" because get(999) was not stubbed
//        System.out.println(mockedList.get(999));
//
//        //Although it is possible to verify a stubbed invocation, usually it's just redundant
//        //If your code cares what get(0) returns then something else breaks (often before even verify() gets executed).
//        //If your code doesn't care what get(0) returns then it should not be stubbed. Not convinced? See here.
//        verify(mockedList).get(0);
//    }
//
//    //argThat
//    @Test
//    public void artThatTest() {
//        Collaborator collaborator = mock(Collaborator.class);
//
//        Mockito.when(collaborator.documentAdded(Mockito.argThat(new ArgMatcher()))).thenReturn("aa");
//    }
//
//    class ArgMatcher extends ArgumentMatcher {
//        @Override
//        public boolean matches(Object o) {
//            logger.debug("matcher:" + o.toString());
//
//            return false;
//        }
//    }
//
//    @Test
//    public void testVoidMethod(){
//        ClassUnderTest classUnderTest = mock(ClassUnderTest.class);
//        doNothing().when(classUnderTest).getFoo(Mockito.argThat(new ArgMatcherString()));
//        classUnderTest.getFoo("abc");
//        verify(classUnderTest).getFoo("abc");
//
//    }
//
//    class ArgMatcherString extends ArgumentMatcher<String> {
//        @Override
//        public boolean matches(Object o) {
//            logger.debug("matcher:" + o.toString());
//
//            return true;
//        }
//    }
//}
